package com.scaffold.springmvc.util.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.AsyncContext;

public class MyThread implements Runnable {
	private AsyncContext asyncContext;

	public MyThread(AsyncContext asyncContext) {
		this.asyncContext = asyncContext;
	}

	public void run() {
		PrintWriter out = null;
		try {
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			out = asyncContext.getResponse().getWriter();
			out.println("myTask starts:" + new Date() + "<br>");
			out.flush();

			out.print("myTask ends:" + new Date() + "<br>");
			out.flush();
			asyncContext.complete();

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != out) {
				out.close();
			}
		}
	}

}